package com.shuai.clientsdk.utils;

import cn.hutool.crypto.digest.DigestAlgorithm;
import cn.hutool.crypto.digest.Digester;
import org.apache.commons.lang3.StringUtils;

/**
 * 签名工具类
 */
public class AuthenticationSignUtils {

    /**
     * 生成签名。参数顺序：api-key，api-secret，timestamp，payload
     */
    public static String generateSign(String apiKey, String apiSecret, long timestamp, Object requestParam) {
        if (StringUtils.isAnyBlank(apiKey, apiSecret)) {
            return "";
        }
        String content = StringUtils.join(apiKey, apiSecret, timestamp, requestParam, "#");
        Digester digester = new Digester(DigestAlgorithm.SHA256);
        return digester.digestHex(content);
    }
}
